package com.surendra.coffeemaker;
import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;



public class CoffeeMakerTest {
public static CoffeeMaker cMaker;
public static Recipe r;
public static Inventory iInventory;
	@Before
	public void setUp() throws Exception {
		cMaker=new CoffeeMaker();
		r= new Recipe();
		iInventory= new Inventory();
		
	}

	@After
	public void tearDown() throws Exception {
		cMaker=null;
		r=null;
	}

	@Test
	/**
	 * Tests (test case 1: addRecipe1) whether recipe is added or not
	 */
	public void addRecipeTest() {
		r.setName("Coffee");
		r.setPrice(50);
		r.setAmtCoffee(3);
		r.setAmtMilk(1);
		r.setAmtSugar(1);
		r.setAmtChocolate(0);
		String expected="Coffee successfully added.";
	
		
		assertTrue(expected,cMaker.addRecipe(r));
				}

@Test
/*
 * Test case 2:deleteRecipe1: a Recipe is deleted
 */
public void deleteRecipeTest(){
	r.setName("Coffee");
	r.setPrice(50);
	r.setAmtCoffee(3);
	r.setAmtMilk(1);
	r.setAmtSugar(1);
	r.setAmtChocolate(0);
	cMaker.addRecipe(r);
	
	String expected="successfully deleted.";
	assertTrue(expected,cMaker.deleteRecipe(r));
}
@Test
/**
 * Test case 3 : editRecipe1 : Recipe is edited
 */
public void editRecipeTest(){
	r.setName("Coffee");
	r.setPrice(50);
	r.setAmtCoffee(3);
	r.setAmtMilk(1);
	r.setAmtSugar(1);
	r.setAmtChocolate(0);
	cMaker.addRecipe(r);
	Recipe current= new Recipe();
	current.setName("Coffee");
	current.setPrice(40);
	current.setAmtCoffee(8);
	current.setAmtMilk(4);
	current.setAmtSugar(2);
	current.setAmtChocolate(3);
	cMaker.editRecipe(r, current);
	assertEquals(40, cMaker.getRecipeForName("Coffee").getPrice());
}@Test
/**
 * Test case 4 : addInventory1 : tests for amount whether it is added to total inventory
 */public void addInventoryTest(){
	cMaker.addInventory(4, 4, 4, 4);
	assertEquals(19, cMaker.checkInventory().getChocolate());
	assertEquals(19,cMaker.checkInventory().getCoffee());
	assertEquals(19,cMaker.checkInventory().getMilk());
	assertEquals(19, cMaker.checkInventory().getSugar());
}@Test
/**
 * Test case 5 : addInventory2: tests for amount less than zero
 */public void addInventoryLessThanZeroTest(){
	assertFalse(cMaker.addInventory(-1,-1,-1,-1));
}@Test
/**
 * Test case 6: check inventory
 */public void checkInventoryTest(){
	assertEquals(15,cMaker.checkInventory().getCoffee());
}@Test
/**
 * Test case 7: purchase Beverage1 and see whether inventory is reduced by the purchase amt
 */public void makeCoffeeTest(){
	r.setName("Coffee");
	r.setPrice(50);
	r.setAmtCoffee(3);
	r.setAmtMilk(1);
	r.setAmtSugar(1);
	r.setAmtChocolate(0);
	int result=cMaker.makeCoffee(r, 65);
	assertEquals(15,result);
	assertEquals(12,iInventory.getCoffee());
	assertEquals(14,iInventory.getMilk());
	assertEquals(14, iInventory.getSugar());
	assertEquals(14, iInventory.getChocolate());
}
}